********************************************************************************
* REGRESSION TABLE WITH CONTROL FOR INDUSTRY CONCENTRATION *********************
********************************************************************************
use ${orig}/industryemployment_sa.dta, clear
sum amr
global N = `r(max)'
keep  eventdate totemployment_sa w93_2 amr
by eventdate amr, sort: egen tot_amr = total(totemployment_sa)
gen share = (totemployment_sa/tot_amr)^2
by eventdate amr, sort: egen herfindahl = total(share)

keep eventdate herfindahl amr
duplicates drop
reshape wide herfindahl, i(eventdate) j(amr)
tsset eventdate
gen idtime = _n

** seasonal adjustment of industry concentrations series at city level:
forv n = 1(1)$N {
qui: seasonallyadjust herfindahl`n', gen(herfindahl_sa`n') ar(1) ma(1) x11 multiplicative replace
qui: replace herfindahl_sa`n' = herfindahl_sa`n'^.5
qui: gen logH_sa`n' = ln(herfindahl_sa`n')	
qui: reg logH_sa`n' idtime 
qui: mat A = e(b)
qui: mat B = e(V)
qui: gen cycle_linear_H_sa`n' = logH_sa`n' - A[1,1]*idtime - A[1,2]
}

keep cycle_linear_H_sa* eventdate herfindahl_sa*
reshape long cycle_linear_H_sa herfindahl_sa, i(eventdate) j(amr)

** merge data on instantaneous volatility: 
merge 1:1 eventdate amr using instanvolatest1.dta
drop if _merge==1
drop _merge

xtset amr eventdate
gen logH = cycle_linear_H_sa
gen laglogH = l.logH
gen lagcycle_linear_sharep99_sa = l1.cycle_linear_sharep99_sa

qui: tab eventdate, gen(date_)
xtreg roll  laglogH date_*, fe vce(robust)
est store m2
xtreg roll  lagcycle_linear_sharep99_sa laglogH date_*, fe vce(robust)
est store m3

esttab m2 m3 using ${tables}/istantaneousvolatcontrol.tex, label r2 replace star(* 0.10 ** 0.05 *** 0.01)
********************************************************************************
